const path = require('path');
const webpack = require('webpack');
const { merge } = require("webpack-merge");
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');

const baseConfig = require("./webpack.base.js");
const BASE_API = '/prod-api';

const config = {
  mode: 'production',
  devtool: false,
  plugins: [
    new webpack.DefinePlugin({
      'process.env.BASE_API': JSON.stringify(BASE_API)
    }),
    new CleanWebpackPlugin(),
    new CopyWebpackPlugin({
      patterns: [{
        from: path.resolve(__dirname, '..', 'public'),
        to: path.resolve(__dirname, '..', 'dist'),
        globOptions: {
          ignore: [
            '**/public/index.html'
          ],
        }
      }]
    })
  ]
};

module.exports = merge([
  baseConfig,
  config
]);